home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / tsrsrc22.arc / RAMFREE.ASM < prev    next >
Assembly Source File  |  1985-06-27  |  2KB  |  61 lines

  1. ;RAMFREE
  2. ;determine amount of available RAM without using CHKDSK
  3. ;Kim Kokkonen, TurboPower Software, 6/85, 408-378-3672
  4. ;written for CHeap ASseMbler
  5. ;Microsoft assembler requires minor modifications
  6. ;only works for up to 640K bytes
  7. ;
  8. ramfree    proc    far
  9.  
  10. ;shrink memory available to this program
  11.     mov    ah,4AH
  12.     mov    bx,offset(theend)
  13.     mov    cl,4
  14.     shr    bx,cl        ;convert bytes to paragraphs
  15.     inc    bx        ;round up to be safe
  16.     int    21H        ;DOS SETBLOCK function
  17.  
  18. ;try to allocate the maximum memory
  19.     mov    ah,4AH
  20.     mov    bx,FFFFH
  21.     int    21H        ;use SETBLOCK again
  22.                 ;BX contains number of paragraphs available
  23.  
  24. ;convert paragraphs to a doubleword number of bytes in dx:ax
  25.     mov    ax,bx
  26.     xor    dx,dx
  27.     mov    dl,ah        ;dl will contain top four bytes of ah
  28.     mov    cl,4
  29.     shr    dx,cl
  30.     shl    ax,cl
  31.  
  32. ;convert doubleword to a six char ASCII number
  33.     mov    bx,offset(nbyts)
  34.     mov    cx,6
  35. filbuf    movb    [bx],' '    ;guarantee 6 spaces in nbytes
  36.     inc    bx        ;set up bx to point to last char in string
  37.     loop    filbuf
  38.  
  39.     mov    si,10        ;prepare to divide by 10
  40. nexdgt    div    ax,si        ;divide dx:ax by si
  41.     or    dx,30H        ;convert remainder to ASCII digit
  42.     dec    bx        ;backup in buffer
  43.     mov    [bx],dl        ;store character
  44.     xor    dx,dx        ;clear remainder
  45.     or    ax,ax        ;all done?
  46.     jnz    nexdgt        ;do next digit
  47.  
  48. ;now output the string
  49.     mov    dx,offset(bmess$)
  50.     mov    ah,09H
  51.     int    21H        ;print string
  52.  
  53. ;exit
  54.     int    20H
  55.     
  56.  
  57. ;data area
  58. bmess$    db    13,10,'RAM bytes available: '
  59. nbyts    db    0,0,0,0,0,0,13,10,36 ;will hold ASCII number of bytes
  60.  
  61. theend    endp